package com.situ.mall.controller;

import com.situ.mall.pojo.Product;
import com.situ.mall.pojo.query.ProductQuery;
import com.situ.mall.service.IProductService;
import com.situ.mall.util.LayUITableResult;
import com.situ.mall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

// case sensitive
@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @RequestMapping("/add")
    @ResponseBody
    public Result add(Product product) {
        productService.add(product);
        return Result.ok("添加成功");
    }

    @RequestMapping("/toAdd")
    public String toAdd() {
        return "product/add";
    }

    @RequestMapping("/deleteAll")
    @ResponseBody
    public Result deleteAll(Integer[] ids) {
        productService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public Result deleteById(Integer id) {
        productService.deleteById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/toList")
    public String toList() {
        return "product/list";
    }

    //http://layui.apixx.net/test/table/demo1.json.js?page=1&limit=10
    //http://127.0.0.1:8087/product/list?page=1&limit=10
    //http://localhost:8087/product/list?page=1&limit=10&productname=zhangsan&email=ss
    @RequestMapping("/list")
    @ResponseBody
    public LayUITableResult list(ProductQuery productQuery) {
        LayUITableResult layUITableResult = productService.list(productQuery);
        return layUITableResult;
    }

    /*@RequestMapping("/list")
    @ResponseBody
    public List<Product> list(Integer id) {
        List<Product> list = productService.list();
        return list;
    }*/
}
